package cn.kone.controller;

import cn.kone.domain.User;
import cn.kone.exception.BusinessException;
import cn.kone.service.ILoginService;
import cn.kone.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;


    @PostMapping
    public R<String> login(@RequestBody User user) {

        String token = null;
        try {
            token = loginService.login(user);
        }catch (BusinessException b) {
            b.printStackTrace();
            return R.fail(b.getMessage());
        }
        catch (Exception e) {
            e.printStackTrace();
            return R.fail();
        }
        return R.ok("登陆成功",token);

    }

}
